/**************************************AJAXFUNC Start******************************************/
function ajaxFunc(options){
    ajaxFunc.opts = mui.extend({}, ajaxFunc.defaults, options);
    ajaxFunc.goJax();
}
ajaxFunc.defaults={
    url : '',
    type : 'POST',
    async : true,
    dataType : 'json',
    headers:{'Content-Type':'application/json'},
    timeout: 10000,
    data : {},
    cache : true,
    error : null,
    complete : null,
    success : null,
    success_zero: null,
    success_second:null
};
ajaxFunc.goJax = function(){
    mui.loading();

    mui.ajax(ajaxFunc.opts.url,{
        data: ajaxFunc.opts.data,
        dataType: ajaxFunc.opts.dataType,
        type: ajaxFunc.opts.type,
        timeout: ajaxFunc.opts.timeout,
        headers: ajaxFunc.opts.headers,
        success:function(data){
            switch (data.resultCode) {
                case 0:
                    mui.alert(data.resultMsg, '提示');
                    if( ajaxFunc.opts.success_zero ){
                        ajaxFunc.opts.success_zero( data );
                    }
                    break;
                case 1:
                    if( ajaxFunc.opts.success ){
                        ajaxFunc.opts.success( data );
                    }
                    break;
                case 2:

                    break;
                case -1:

                    break;
            }
            mui.loading('close');
        },
        error:function(xhr,type,errorThrown){
            //异常处理；
            mui.loading('close');
            mui.alert('服务器未响应', '提示');
            if( ajaxFunc.opts.error ){
                ajaxFunc.opts.error(xhr,type,errorThrown);
            }
        }
    });
};
/**************************************JQ AJAXFUNC End**********************************/
//时间戳转日期
Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};
//全局A链接跳转
 mui('body').on('tap','a.a-link',function(){document.location.href=this.href;});  